<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        span{
            color: red;
        }
    </style>
</head>
<body>
<label>用户名<input type="text"><span id="s1"></span></label>
<br>
<label>密码<input type="password"><span id="s2"></span></label>
<br>
<input type="button" value="提交" id="i1">

<script src="jquery.js"></script>
<script>
    $("#i1").click(function(){
        if ($("[type='text']").val().trim() === ""){
            $("#s1").text("用户名不能为空！");
            $("[type='text']").val("");
        }else{
            $("#s1").text("");
        }
        if ($("[type='password']").val().trim() === ""){
            $("#s2").text("密码不能为空！");
            $("[type='password']").val("");
        }else{
            $("#s2").text("");
        }
    })
</script>
</body>
</html>